package service;

import dao.UserOperation;
import pojo.User;
import utils.JdbcUtils;

import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author fire'ge
 */
public class LoginService {
    public static User checkLogin(String username,String pwd) throws SQLException, IOException {
        Connection connection = JdbcUtils.getConnection();
        ResultSet resultSet = UserOperation.checkLogin(username,pwd,connection);
        User user = null;
        while(resultSet. next()){
            int id = resultSet.getInt(1);
            String trueUsername = resultSet.getString(2);
            String turePwd = resultSet.getString(3);
            int right = resultSet.getInt(4);
            if (trueUsername != null && turePwd != null && id != 0){
                user = new User(id,trueUsername,turePwd,right);
            }
        }
        connection.close();
        return user;
    }
}
